/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.mad.bikepony.model;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.model.BaseModel;
import com.liferay.portal.model.impl.BaseModelImpl;

import com.mad.bikepony.service.DeliveryLocalServiceUtil;

import java.io.Serializable;

import java.lang.reflect.Proxy;

import java.util.HashMap;
import java.util.Map;

/**
 * @author nicola
 */
public class DeliveryClp extends BaseModelImpl<Delivery> implements Delivery {
	public DeliveryClp() {
	}

	public Class<?> getModelClass() {
		return Delivery.class;
	}

	public String getModelClassName() {
		return Delivery.class.getName();
	}

	public long getPrimaryKey() {
		return _deliveryId;
	}

	public void setPrimaryKey(long primaryKey) {
		setDeliveryId(primaryKey);
	}

	public Serializable getPrimaryKeyObj() {
		return new Long(_deliveryId);
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("deliveryId", getDeliveryId());
		attributes.put("deliveryCode", getDeliveryCode());
		attributes.put("trackingCode", getTrackingCode());
		attributes.put("senderAddress", getSenderAddress());
		attributes.put("senderAdditionalInfo", getSenderAdditionalInfo());
		attributes.put("senderEmail", getSenderEmail());
		attributes.put("recipientAddress", getRecipientAddress());
		attributes.put("recipientAdditionalInfo", getRecipientAdditionalInfo());
		attributes.put("recipientEmail", getRecipientEmail());
		attributes.put("state", getState());
		attributes.put("agentId", getAgentId());
		attributes.put("submissionTimestamp", getSubmissionTimestamp());
		attributes.put("pickupTimestamp", getPickupTimestamp());
		attributes.put("deliveryTimestamp", getDeliveryTimestamp());
		attributes.put("recipientSignature", getRecipientSignature());
		attributes.put("estimatedPickupTime", getEstimatedPickupTime());
		attributes.put("estimatedDeliveryTime", getEstimatedDeliveryTime());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long deliveryId = (Long)attributes.get("deliveryId");

		if (deliveryId != null) {
			setDeliveryId(deliveryId);
		}

		String deliveryCode = (String)attributes.get("deliveryCode");

		if (deliveryCode != null) {
			setDeliveryCode(deliveryCode);
		}

		String trackingCode = (String)attributes.get("trackingCode");

		if (trackingCode != null) {
			setTrackingCode(trackingCode);
		}

		String senderAddress = (String)attributes.get("senderAddress");

		if (senderAddress != null) {
			setSenderAddress(senderAddress);
		}

		String senderAdditionalInfo = (String)attributes.get(
				"senderAdditionalInfo");

		if (senderAdditionalInfo != null) {
			setSenderAdditionalInfo(senderAdditionalInfo);
		}

		String senderEmail = (String)attributes.get("senderEmail");

		if (senderEmail != null) {
			setSenderEmail(senderEmail);
		}

		String recipientAddress = (String)attributes.get("recipientAddress");

		if (recipientAddress != null) {
			setRecipientAddress(recipientAddress);
		}

		String recipientAdditionalInfo = (String)attributes.get(
				"recipientAdditionalInfo");

		if (recipientAdditionalInfo != null) {
			setRecipientAdditionalInfo(recipientAdditionalInfo);
		}

		String recipientEmail = (String)attributes.get("recipientEmail");

		if (recipientEmail != null) {
			setRecipientEmail(recipientEmail);
		}

		Integer state = (Integer)attributes.get("state");

		if (state != null) {
			setState(state);
		}

		Long agentId = (Long)attributes.get("agentId");

		if (agentId != null) {
			setAgentId(agentId);
		}

		Long submissionTimestamp = (Long)attributes.get("submissionTimestamp");

		if (submissionTimestamp != null) {
			setSubmissionTimestamp(submissionTimestamp);
		}

		Long pickupTimestamp = (Long)attributes.get("pickupTimestamp");

		if (pickupTimestamp != null) {
			setPickupTimestamp(pickupTimestamp);
		}

		Long deliveryTimestamp = (Long)attributes.get("deliveryTimestamp");

		if (deliveryTimestamp != null) {
			setDeliveryTimestamp(deliveryTimestamp);
		}

		String recipientSignature = (String)attributes.get("recipientSignature");

		if (recipientSignature != null) {
			setRecipientSignature(recipientSignature);
		}

		Long estimatedPickupTime = (Long)attributes.get("estimatedPickupTime");

		if (estimatedPickupTime != null) {
			setEstimatedPickupTime(estimatedPickupTime);
		}

		Long estimatedDeliveryTime = (Long)attributes.get(
				"estimatedDeliveryTime");

		if (estimatedDeliveryTime != null) {
			setEstimatedDeliveryTime(estimatedDeliveryTime);
		}
	}

	public long getDeliveryId() {
		return _deliveryId;
	}

	public void setDeliveryId(long deliveryId) {
		_deliveryId = deliveryId;
	}

	public String getDeliveryCode() {
		return _deliveryCode;
	}

	public void setDeliveryCode(String deliveryCode) {
		_deliveryCode = deliveryCode;
	}

	public String getTrackingCode() {
		return _trackingCode;
	}

	public void setTrackingCode(String trackingCode) {
		_trackingCode = trackingCode;
	}

	public String getSenderAddress() {
		return _senderAddress;
	}

	public void setSenderAddress(String senderAddress) {
		_senderAddress = senderAddress;
	}

	public String getSenderAdditionalInfo() {
		return _senderAdditionalInfo;
	}

	public void setSenderAdditionalInfo(String senderAdditionalInfo) {
		_senderAdditionalInfo = senderAdditionalInfo;
	}

	public String getSenderEmail() {
		return _senderEmail;
	}

	public void setSenderEmail(String senderEmail) {
		_senderEmail = senderEmail;
	}

	public String getRecipientAddress() {
		return _recipientAddress;
	}

	public void setRecipientAddress(String recipientAddress) {
		_recipientAddress = recipientAddress;
	}

	public String getRecipientAdditionalInfo() {
		return _recipientAdditionalInfo;
	}

	public void setRecipientAdditionalInfo(String recipientAdditionalInfo) {
		_recipientAdditionalInfo = recipientAdditionalInfo;
	}

	public String getRecipientEmail() {
		return _recipientEmail;
	}

	public void setRecipientEmail(String recipientEmail) {
		_recipientEmail = recipientEmail;
	}

	public int getState() {
		return _state;
	}

	public void setState(int state) {
		_state = state;
	}

	public long getAgentId() {
		return _agentId;
	}

	public void setAgentId(long agentId) {
		_agentId = agentId;
	}

	public long getSubmissionTimestamp() {
		return _submissionTimestamp;
	}

	public void setSubmissionTimestamp(long submissionTimestamp) {
		_submissionTimestamp = submissionTimestamp;
	}

	public long getPickupTimestamp() {
		return _pickupTimestamp;
	}

	public void setPickupTimestamp(long pickupTimestamp) {
		_pickupTimestamp = pickupTimestamp;
	}

	public long getDeliveryTimestamp() {
		return _deliveryTimestamp;
	}

	public void setDeliveryTimestamp(long deliveryTimestamp) {
		_deliveryTimestamp = deliveryTimestamp;
	}

	public String getRecipientSignature() {
		return _recipientSignature;
	}

	public void setRecipientSignature(String recipientSignature) {
		_recipientSignature = recipientSignature;
	}

	public long getEstimatedPickupTime() {
		return _estimatedPickupTime;
	}

	public void setEstimatedPickupTime(long estimatedPickupTime) {
		_estimatedPickupTime = estimatedPickupTime;
	}

	public long getEstimatedDeliveryTime() {
		return _estimatedDeliveryTime;
	}

	public void setEstimatedDeliveryTime(long estimatedDeliveryTime) {
		_estimatedDeliveryTime = estimatedDeliveryTime;
	}

	public void setRecipientSignatureImage(byte[] image) {
		throw new UnsupportedOperationException();
	}

	public com.mad.bikepony.model.Agent getAgent() {
		throw new UnsupportedOperationException();
	}

	public byte[] getRecipientSignatureImage() {
		throw new UnsupportedOperationException();
	}

	public BaseModel<?> getDeliveryRemoteModel() {
		return _deliveryRemoteModel;
	}

	public void setDeliveryRemoteModel(BaseModel<?> deliveryRemoteModel) {
		_deliveryRemoteModel = deliveryRemoteModel;
	}

	public void persist() throws SystemException {
		if (this.isNew()) {
			DeliveryLocalServiceUtil.addDelivery(this);
		}
		else {
			DeliveryLocalServiceUtil.updateDelivery(this);
		}
	}

	@Override
	public Delivery toEscapedModel() {
		return (Delivery)Proxy.newProxyInstance(Delivery.class.getClassLoader(),
			new Class[] { Delivery.class }, new AutoEscapeBeanHandler(this));
	}

	@Override
	public Object clone() {
		DeliveryClp clone = new DeliveryClp();

		clone.setDeliveryId(getDeliveryId());
		clone.setDeliveryCode(getDeliveryCode());
		clone.setTrackingCode(getTrackingCode());
		clone.setSenderAddress(getSenderAddress());
		clone.setSenderAdditionalInfo(getSenderAdditionalInfo());
		clone.setSenderEmail(getSenderEmail());
		clone.setRecipientAddress(getRecipientAddress());
		clone.setRecipientAdditionalInfo(getRecipientAdditionalInfo());
		clone.setRecipientEmail(getRecipientEmail());
		clone.setState(getState());
		clone.setAgentId(getAgentId());
		clone.setSubmissionTimestamp(getSubmissionTimestamp());
		clone.setPickupTimestamp(getPickupTimestamp());
		clone.setDeliveryTimestamp(getDeliveryTimestamp());
		clone.setRecipientSignature(getRecipientSignature());
		clone.setEstimatedPickupTime(getEstimatedPickupTime());
		clone.setEstimatedDeliveryTime(getEstimatedDeliveryTime());

		return clone;
	}

	public int compareTo(Delivery delivery) {
		long primaryKey = delivery.getPrimaryKey();

		if (getPrimaryKey() < primaryKey) {
			return -1;
		}
		else if (getPrimaryKey() > primaryKey) {
			return 1;
		}
		else {
			return 0;
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		DeliveryClp delivery = null;

		try {
			delivery = (DeliveryClp)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		long primaryKey = delivery.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(35);

		sb.append("{deliveryId=");
		sb.append(getDeliveryId());
		sb.append(", deliveryCode=");
		sb.append(getDeliveryCode());
		sb.append(", trackingCode=");
		sb.append(getTrackingCode());
		sb.append(", senderAddress=");
		sb.append(getSenderAddress());
		sb.append(", senderAdditionalInfo=");
		sb.append(getSenderAdditionalInfo());
		sb.append(", senderEmail=");
		sb.append(getSenderEmail());
		sb.append(", recipientAddress=");
		sb.append(getRecipientAddress());
		sb.append(", recipientAdditionalInfo=");
		sb.append(getRecipientAdditionalInfo());
		sb.append(", recipientEmail=");
		sb.append(getRecipientEmail());
		sb.append(", state=");
		sb.append(getState());
		sb.append(", agentId=");
		sb.append(getAgentId());
		sb.append(", submissionTimestamp=");
		sb.append(getSubmissionTimestamp());
		sb.append(", pickupTimestamp=");
		sb.append(getPickupTimestamp());
		sb.append(", deliveryTimestamp=");
		sb.append(getDeliveryTimestamp());
		sb.append(", recipientSignature=");
		sb.append(getRecipientSignature());
		sb.append(", estimatedPickupTime=");
		sb.append(getEstimatedPickupTime());
		sb.append(", estimatedDeliveryTime=");
		sb.append(getEstimatedDeliveryTime());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(55);

		sb.append("<model><model-name>");
		sb.append("com.mad.bikepony.model.Delivery");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>deliveryId</column-name><column-value><![CDATA[");
		sb.append(getDeliveryId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>deliveryCode</column-name><column-value><![CDATA[");
		sb.append(getDeliveryCode());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>trackingCode</column-name><column-value><![CDATA[");
		sb.append(getTrackingCode());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>senderAddress</column-name><column-value><![CDATA[");
		sb.append(getSenderAddress());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>senderAdditionalInfo</column-name><column-value><![CDATA[");
		sb.append(getSenderAdditionalInfo());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>senderEmail</column-name><column-value><![CDATA[");
		sb.append(getSenderEmail());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>recipientAddress</column-name><column-value><![CDATA[");
		sb.append(getRecipientAddress());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>recipientAdditionalInfo</column-name><column-value><![CDATA[");
		sb.append(getRecipientAdditionalInfo());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>recipientEmail</column-name><column-value><![CDATA[");
		sb.append(getRecipientEmail());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>state</column-name><column-value><![CDATA[");
		sb.append(getState());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>agentId</column-name><column-value><![CDATA[");
		sb.append(getAgentId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>submissionTimestamp</column-name><column-value><![CDATA[");
		sb.append(getSubmissionTimestamp());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>pickupTimestamp</column-name><column-value><![CDATA[");
		sb.append(getPickupTimestamp());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>deliveryTimestamp</column-name><column-value><![CDATA[");
		sb.append(getDeliveryTimestamp());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>recipientSignature</column-name><column-value><![CDATA[");
		sb.append(getRecipientSignature());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>estimatedPickupTime</column-name><column-value><![CDATA[");
		sb.append(getEstimatedPickupTime());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>estimatedDeliveryTime</column-name><column-value><![CDATA[");
		sb.append(getEstimatedDeliveryTime());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private long _deliveryId;
	private String _deliveryCode;
	private String _trackingCode;
	private String _senderAddress;
	private String _senderAdditionalInfo;
	private String _senderEmail;
	private String _recipientAddress;
	private String _recipientAdditionalInfo;
	private String _recipientEmail;
	private int _state;
	private long _agentId;
	private long _submissionTimestamp;
	private long _pickupTimestamp;
	private long _deliveryTimestamp;
	private String _recipientSignature;
	private long _estimatedPickupTime;
	private long _estimatedDeliveryTime;
	private BaseModel<?> _deliveryRemoteModel;
}